<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
  String path = request.getContextPath();
  String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
  String _id=request.getParameter("_");
  String jsessionid = session.getId();
%>

        <div class="panel">
            <div class="panel-heading header">
                <h3 class="panel-title" id="title">费用报销</h3>
            </div>

            <!-- BASIC FORM ELEMENTS -->
            <!--===================================================-->
            <form id="form_expense_input" class="form-horizontal">

                <input type="hidden" name="keyId" id="keyId" value="${expense.id}"/>

                <div class="form-group">
                    <label class="col-md-2 control-label">报销类别<i class="fa fa-asterisk txt-color-red"></i></label>
                    <div class="col-md-6">
                        <select name="typeDictId" id="typeDictId" class="form-control">
                            <option></option>
                            <c:forEach var="item" items="${expenseTypeDict}" varStatus="status">
                                <option value="${item.id}" <c:if test="${item.id == expense.type.id}"> selected="selected"</c:if>>${item.name}</option>
                            </c:forEach>
                        </select>
                    </div>
                </div>

                <div class="form-group" >
                    <label class="col-md-2 control-label">
                        报销金额（元）<i class="fa fa-asterisk txt-color-red"></i>
                    </label>
                    <div class="col-md-6">
                        <input type="text" name="amount" id="amount" class="form-control" placeholder="请输入报销金额（元）" value="${expense.amount}" >
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-md-2 control-label">
                        费用说明
                    </label>
                    <div class="col-md-6">
                        <input type="text" name="content" id="content" class="form-control" placeholder="请输入费用说明" value="${expense.content}" >
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-md-2 control-label">发票照片</label>
                    <div class="col-md-6">
                        <input name="uploadify" id="picname" placeholder="" type="file" >
                        <input name="picId" id="picId" style="display: none" value="${picId}">
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-md-2 control-label">其他附件</label>
                    <div class="col-md-6">
                        <input name="uploadify" id="filename" placeholder="" type="file" >
                        <input name="fileId" id="fileId" style="display: none" value="${fileId}">
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-md-2 control-label">
                        是否抄送
                    </label>
                    <div class="col-md-6">
                        <div class="radio">
                            <input type="radio" id="remindYes" name="remind" value="1" class="magic-radio">
                            <label for="remindYes">是</label>
                            <input type="radio" id="remindNo" name="remind" value="0" class="magic-radio">
                            <label for="remindNo">否</label>
                        </div>
                    </div>
                </div>

                <div class="form-group" style="display: none" id="showRemind">
                    <label class="col-md-2 control-label">
                        <a href="javascript:void(0);" onclick="fn_members_dialog_select('remindUser', 'remindUserId')" style="color: #4FA5D0">抄送人员</a>
                        <i class="fa fa-asterisk txt-color-red"></i>
                    </label>
                    <div class="col-md-6">
                        <input type="text" id="remindUser" name="remindUser" class="form-control" placeholder="请选择抄送人员" readonly  onclick="fn_members_dialog_select('remindUser', 'remindUserId')">
                        <input type="hidden" id="remindUserId" name="remindUserId" value="">
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-md-2 control-label">
                       下一步流程
                    </label>
                    <div class="col-md-6">
                        <div class="radio">
                            <input type="radio" id="nextNo" name="next" value="0" class="magic-radio">
                            <label for="nextNo">归档</label>
                            <input type="radio" id="nextYes" name="next" value="1" class="magic-radio">
                            <label for="nextYes">选择下一步操作人</label>
                        </div>
                    </div>
                </div>

                <div class="form-group" style="display:none" id="showNextStep">
                    <label class="col-md-2 control-label">
                        <a href="javascript:void(0);" onclick="fn_member_dialog_select('editors', 'editorsId')" style="color: #4FA5D0">选择下一步操作人</a>
                        <i class="fa fa-asterisk txt-color-red"></i>
                    </label>
                    <div class="col-md-6">
                        <input type="text" id="editors" name="editors" class="form-control" placeholder="请选择下一步操作人" readonly onclick="fn_member_dialog_select('editors', 'editorsId')" >
                        <input type="hidden" id="editorsId" name="editorsId">
                    </div>
                </div>
            </form>
            <!--===================================================-->
            <!-- END BASIC FORM ELEMENTS -->

            <div class="panel-footer">
                <a class="btn btn-default" id="apply-re-common" href="javascript:void(0)">
                    <i class="fa fa-lg fa-mail-reply"></i> 返回
                </a>
                <a class="btn btn-success" id="btn-save-common" href="javascript:void(0);"><i class="fa fa-lg fa-download"></i> 保存 </a>
                <c:if test="${expense==null || expense.processState=='Draft'}">
                    <a class="btn btn-warning" id="btn-commit-common" href="javascript:void(0);"><i class="fa fa-upload"></i> 提交 </a>
                </c:if>
                <c:if test="${expense!=null &&  expense.processState=='Backed'}">
                    <a class="btn btn-warning" id="btn-recommit-common" href="javascript:void(0);"><i class="fa fa-upload"></i> 再提交 </a>
                </c:if>
            </div>
        </div>

<script>
    var index = "${index}";
    var todo = "${todo}";
    var remind = "${remind}";
    var record = "${record}";
    var draft =  "${draft}";


    $(function(){
        var pdata= {
            keyId:$("#keyId").val(),
            entityName:"com.fz.us.oa.core.entity.com.Expense"
        };
        fn_expense_input_validate();
    });

    // 照片上传
    inputLoad({
        objId:"picname",
        entityName:"picIds",
        sourceId:"picId",
        jsessionid:"<%=jsessionid%>"
    });
    // 附件上传
    inputLoad({
        objId:"filename",
        entityName:"fileIds",
        sourceId:"fileId",
        jsessionid:"<%=jsessionid%>"
    });

    // 字典列表下拉框
    $("#typeDictId").select2({
        placeholder: "请选择一个报销类别",
        allowClear: true
    });


    //下一步点击
    $(':radio[name="next"]').click(function(){
        if($(this).val() == "1"){
            $('#showNextStep').show();
        }else{
            $('#showNextStep').hide();
        }
    });

    //抄送点击
    $(':radio[name="remind"]').click(function(){
        if($(this).val() == "1"){
            $('#showRemind').show();
        }else{
            $('#showRemind').hide();
        }
    });

    // 表单数据校验
    function fn_expense_input_validate() {
        __init_validate('form_expense_input', {
            rules : {
                typeDictId:{
                    required : true
                },
                amount:{
                    required : true,
                    number:true
                },
                content:{
                    required : true
                },
                picIds:{
                    required:true
                },
                fileIds:{
                    required:true
                },
                next:{
                    required:true
                },
                editorsId:{
                    required:function(){
                        if($(':checked[name="next"]').val() == "3"){
                            return true;
                        }else{
                            return false;
                        }
                    }
                }
            },
            messages : {
                typeDictId:{
                    required : "请选择报销类别"
                },
                amount:{
                    required : "请输入报销金额",
                    number: "报销金额必须为数字"
                },
                content:{
                    required : "请输入费用说明"
                },
                picIds:{
                    required:"请上传发票照片"
                },
                fileIds:{
                    required:"请上传其他附件"
                },
                next:{
                    required:"请选择下一步流程"
                },
                editorsId:{
                    required: "请选择下一步操作人"
                }
            }
        });
    }
    //保存
    $("#btn-save-common").click(
            function(e) {
                __confirm_dialog("提示：","确定保存吗？",
                        function () {
                            __form_save("form_expense_input", "<%=path%>/com/expense/save",function(){
                                $("#apply-re-common").trigger("click");
                            })
                        }
                )
            }
    );

    //提交
    $("#btn-commit-common,#btn-recommit-common").click(
            function(e) {
                if (!$('#form_expense_input').valid()) {
                    return false;
                }

                __confirm_dialog("提示：","确定提交么?",
                        function () {
                            __form_save("form_expense_input", "<%=path%>/com/expense/commit",function(){
                                $("#apply-re-common").trigger("click");
                            })
                        }
                )
            }
    );


    //返回视图
    $("#apply-re-common").click(function(){

        if(index==1){
            loadURL("menu/dashboard",$('#page-content'));
        }else if(todo==1){
            loadURL("menu/toDo",$('#page-content'));
        }else if(remind==1){
            loadURL("menu/remind",$('#page-content'));
        }else if(record==1){
            loadURL("menu/taskRecord?type=1",$('#page-content'));
        }else if(record==2){
            loadURL("menu/taskRecord?type=2",$('#page-content'));
        }else if(draft==1){
            loadURL("menu/draft",$('#page-content'));
        }else{
            returnToHashUrl()
        }
    });




</script>




